<?php
/**
 * Created by PhpStorm.
 * User: liutim
 * Date: 2017/10/31
 * Time: 上午6:18
 */
//反馈回浏览器时使用json数据
header('Content-Type: application/json;charset=utf-8');
header('Access-Control-Allow-Origin:http://localhost:3333');
//获取浏览器通过contenttype=application/json提交上来的数据。
//不同于表单提交(form)时的$_POST['userName']
$postStr=isset($GLOBALS['HTTP_RAW_POST_DATA'])?$GLOBALS['HTTP_RAW_POST_DATA']:file_get_contents("php://input");
//拿到的json字符串进行解码，会根据情况返回对象或者数组
$x=json_decode($postStr);
$username=$x->userName;
$password=$x->passWord;

if($username== "123" && $password == "123" )
{
    $user['id']=$username;
    $user['name']=$password;

    session_start();
    $_SESSION['user']=$user;
    echo '{"message":"success"}';
}else{
    echo '{"message":"error"}';
}

